//
//  TopView.swift
//  知乎日报
//
//  Created by Ann on 2017/10/12.
//  Copyright © 2017年 Ann. All rights reserved.
//

import UIKit
let iconMargin:CGFloat = 10.0
let topView_equalWidth:CGFloat = userScreenWidth / 3
let userViewLabelColor:UIColor = UIColor.white

class TopView: UIView {
  
    lazy var userIcon:UIImageView = {
    let image =  UIImageView()
        image.image = UIImage(named: "Setting_Avatar")
      image.layer.cornerRadius = 15
    
       image.clipsToBounds = true
    return image
    }()
  lazy var userName:UILabel = {
    let lab = UILabel()
        lab.text = "请登录"
        lab.font = UIFont.systemFont(ofSize: 14)
        lab.textColor = userViewLabelColor
    return lab
    }()
   lazy var userCollect:UIButton = {
    let btn = UIButton()
        btn.setImage(UIImage(named:"Menu_Icon_Collect"), for: UIControlState.normal)
    return btn
    }()
   lazy var userMessage:UIButton = {
    let btn = UIButton()
        btn.setImage(UIImage(named:"Menu_Icon_Message"), for: .normal)
        return btn
    }()
   lazy var settingBtn:UIButton = {
    let btn = UIButton()
        btn.setImage(UIImage(named:"Menu_Icon_Setting"), for: UIControlState.normal)
    return btn
    }()
    
   lazy var collectLabel:UILabel = {
    let lab = UILabel()
        lab.text = "收藏"
        lab.font = UIFont.systemFont(ofSize: 10)
        lab.textColor = userViewLabelColor
    return lab
    }()
    
    var messeggeLabel:UILabel = {
       let lab = UILabel()
        lab.text = "消息"
        lab.font = UIFont.systemFont(ofSize: 10)
        lab.textColor = userViewLabelColor

        return lab
    }()
    var settingLabel:UILabel = {
        let lab = UILabel()
        lab.text = "设置"
        lab.font = UIFont.systemFont(ofSize: 10)
        lab.textColor = userViewLabelColor

        return lab
    }()
   override init(frame:CGRect) {
        
    super.init(frame: frame)
        
    backgroundColor = userViewBackground
        
    setupUI()
        
    }
    
    func setupUI(){
        
        
        
    addSubview(userIcon)
    addSubview(userName)
    addSubview(userCollect)
    addSubview(userMessage)
    addSubview(settingBtn)
    addSubview(collectLabel)
    addSubview(messeggeLabel)
    addSubview(settingLabel)
        
  setlayout()
    
    userName.sizeToFit()
   userCollect.sizeToFit() 
   messeggeLabel.sizeToFit()
        
    }
    
    func setlayout(){
    userIcon.snp.makeConstraints { (make) in
        make.left.equalTo(self.snp.left).offset(iconMargin)
        make.top.equalTo(self.snp.top).offset(iconMargin)
        make.width.height.equalTo(30)
    
        }
        
     userName.snp.makeConstraints { (make) in
        make.left.equalTo(userIcon.snp.right).offset(iconMargin)
        make.centerY.equalTo(self.userIcon.snp.centerY)
        }
        
    collectLabel.snp.makeConstraints { (make) in
        make.left.equalTo(self.snp.left).offset(iconMargin)
        make.bottom.equalTo(self.snp.bottom).offset(-iconMargin/2)
        
    }
        
     userCollect.snp.makeConstraints { (make) in
        make.centerX.equalTo(collectLabel.snp.centerX) 
        make.bottom.equalTo(collectLabel.snp.top).offset(-iconMargin/2 )
        
        }
     messeggeLabel.snp.makeConstraints { (make) in
        make.centerX.equalTo(userCollect.snp.centerX).offset(topView_equalWidth)
        make.bottom.equalTo(collectLabel.snp.bottom)
        }
    userMessage.snp.makeConstraints { (make) in
        make.centerX.equalTo(messeggeLabel.snp.centerX)
         make.bottom.equalTo(messeggeLabel.snp.top).offset(-iconMargin/2 )
        }
        
        settingLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(userMessage.snp.centerX).offset(topView_equalWidth)
            make.bottom.equalTo(collectLabel.snp.bottom)
        }
        settingBtn.snp.makeConstraints { (make) in
            make.centerX.equalTo(settingLabel.snp.centerX)
            make.bottom.equalTo(settingLabel.snp.top).offset(-iconMargin/2 )
        }
        
        
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
